
<template>
  <page-header-wrapper :title="false">
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="16">
            <a-col :span="8">
              <a-form-item label="联系电话">
                <a-input v-model="queryParam.contactNumber" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :span="8">
              <a-form-item label="计酬方式">
                <a-select v-model="queryParam.taskUnit" placeholder="请选择" default-value="">
                  <a-select-option value="0">天</a-select-option>
                  <a-select-option value="1">次</a-select-option>
                  <a-select-option value="2">月</a-select-option>
                  <a-select-option value="3">年</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="8" style="text-align: right;">
              <span class="table-page-search-submitButtons">
                <!-- <a-button type="primary" icon="plus" @click="handleAdd">新建</a-button> -->
                <a-button type="primary" style="margin-left: 8px" @click="handleSearch">查询</a-button>
                <a-button style="margin-left: 8px" @click="handleReset">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <s-table
        ref="table"
        size="default"
        :columns="columns"
        :scroll="{x: true}"
        :data="loadData"
        :pageNum="pageNum"
        :pageSize="pageSize"
        rowKey="id">
        <div slot="action" slot-scope="text, record">
          <a type="primary" :disabled="record.state === 1" @click="handleStatus(record)">激活</a>
          <a
            :disabled="record.state === 2"
            @click="handleStatus(record)"
            style="margin-left:10px;">冻结</a>
        </div>
      </s-table>
    </a-card>
    <!-- <create-form
      ref="createModal"
      :visible="visible"
      :loading="confirmLoading"
      :model="mdl"
      @cancel="handleCancel"
      @ok="handleOk" /> -->
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import { jobList, jobActive as active, jobFrozen as frozen} from '@/api/task'
const dict = [{ value: 0, text: '天' }, { value: 1, text: '次' }, { value: 2, text: '月' }, { value: 3, text: '年' }]
const jobDict = [{ value: 0, text: '求职中' }, { value: 1, text: '已工作' }, { value: -1, text: '已关闭' }]
export default {
  name: 'TableList',
  components: {
    STable
  },
  data () {
    return {
      data: [],
      queryParam: {},
      pageNum: 1,
      pageSize: 20,
      visible: false,
      mdl: null,
      columns: [
        {
          title: '求职类型',
          width: 120,
          dataIndex: 'applyType',
          customRender: (val) => {
            return val == 0 ? '全职' : '兼职'
          }
        },
        {
          title: '省',
          width: 100,
          dataIndex: 'province'
        },
        {
          title: '市',
          width: 100,
          dataIndex: 'city'
        },
        {
          title: '区',
          width: 100,
          dataIndex: 'area'
        },
        {
          title: '工作内容期望',
          width: 160,
          dataIndex: 'content'
        },
        {
          title: '联系电话',
          width: 120,
          dataIndex: 'mobile'
        },
        {
          title: '薪资要求',
          width: 120,
          dataIndex: 'salary'
        },
        {
          title: '计酬方式',
          width: 120,
          dataIndex: 'salaryUnit',
          customRender: (val) => {
            const item = dict.find(i => i.value === val)
            return item && item.text
          }
        },
        // {
        //   title: '状态',
        //   width: 120,
        //   dataIndex: 'state'
        // },
        {
          title: '求职状态',
          width: 120,
          dataIndex: 'applyState',
          customRender: (val) => {
            const item = jobDict.find(i => i.value === val)
            return item && item.text
          }
        },
        {
          title: '操作',
          width: 100,
          fixed: 'right',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  created () {
  },
  methods: {
    handleSearch (e) {
      this.$refs.table.refresh()
    },
    handleReset () {
      this.queryParam = {}
      this.$refs.table.refresh()
    },
    loadData (params) {
      return jobList(Object.assign(params, this.queryParam)).then(res => {
        return res.data
      })
    },
    handleStatus (row) {
      const { state, id } = row
      this.$confirm({
        title: `您确定要${state === 1 ? '冻结' : '激活'}它吗？`,
        onOk: () => {
          if (row.state === 1) {
            frozen([id]).then(() => {
              this.$message.success('冻结成功')
              this.$refs.table.refresh()
            })
          } else {
            active([id]).then(() => {
              this.$message.success('激活成功')
              this.$refs.table.refresh()
            })
          }
        }
      })
    }
  }
}
</script>
